package com.liuzy.main;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;

import com.liuzy.mybaties.Mybaties;
import com.sun.grizzly.http.SelectorThread;
import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory;

/**
 * 打包成jar启动项目
 * 
 * @author liuzy
 * @since 2016年5月2日
 */
public class GrizzlyStart {
	public static void main(String[] args) throws IOException {
		Mybaties.init("config.properties");
		final String baseUri = "http://127.0.0.1:80/rest/";
		HashMap<String, String> initParams = new HashMap<String, String>();
		initParams.put("com.sun.jersey.config.property.packages", "com.liuzy.resource");
		initParams.put("com.sun.jersey.api.json.POJOMappingFeature", "true");
		SelectorThread server = GrizzlyWebContainerFactory.create(baseUri, initParams);
		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					new URL(baseUri + "application.wadl").openStream().close();
				} catch (MalformedURLException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}).start();
		System.in.read();
		server.stopEndpoint();
		System.exit(0);
	}
}
